<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<table id="user_list" class="easyui-datagrid"
       fit="true" border="false"
       singleSelect="true" fitColumns="true" pagination="true" toolbar="#toolbar_user"
       idField="userId" url="../../shiro/user/loadList.action">
    <thead>
    <tr>
        <th field="username" width="60">登入名</th>
        <th field="rolenamestr" width="60">角色权限</th>
    </tr>
    </thead>
</table>
<div id="toolbar_user">
    <shiro:hasPermission name="user_add">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="loadWin('添加用户','../../shiro/user/showedit.action?user_id=0')" />
    </shiro:hasPermission>
    <shiro:hasPermission name="user_edit">
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="user_initPassword()" />
    </shiro:hasPermission>
    <shiro:hasPermission name="user_delete">
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="user_remove()"/>
    </shiro:hasPermission>
</div>
<script>
    function user_showedit() {
        //获取选中的列
        var selected = $("#user_list").datagrid("getSelected");
        if(selected==null){
            alert('请选择行！');
        }else{
            //进行编辑操作
            loadWin('编辑用户','../../shiro/user/showedit.action?user_id='+selected.userId);
        }
    }
    //管理员初始化密码
    function user_initPassword() {
    	  //获取选中的列
        var selected = $("#user_list").datagrid("getSelected");
        if(selected==null){
            alert('请选择行！');
        }else{
            //进行编辑操作
            loadWin('编辑用户','../../shiro/user/user_initPassword.action?user_id='+selected.userId);
        }
    }
    
    function user_remove() {
        var selected = $("#user_list").datagrid("getSelected");
        if(selected==null){
            alert('请选择行！');
        }else{
            $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
                if (r){
                    $.post('../../shiro/user/delete.action',{user_id:selected.userId},function (res) {
                        $("#user_list").datagrid("reload");
                    });
                }
            });
        }
    }
</script>
